package cn.ezios.huo.code.factory;

import cn.ezios.huo.code.factory.mb.ColumnMapper;
import cn.hutool.core.util.StrUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class QueryColumns {

    public static void main(String[] args) throws IOException {
        String resource = "mb.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        try(SqlSession session = sqlSessionFactory.openSession()){
            ColumnMapper mapper = session.getMapper(ColumnMapper.class);
            List<Map> mapList = mapper.queryColumns("sys_user");
            for (Map column : mapList) {
                String columnName = (String) column.get("columnName");
                System.out.printf("""
                        {\s
                        \ttitle: '%s',\s
                        \tdataIndex: '%s'\s
                        },
                        """, column.get("columnComment"), StrUtil.toCamelCase(columnName));
            }
            for(Map column : mapList){
                String columnName = (String) column.get("columnName");
                System.out.printf("      <a-form-item label=\"%s\">\n" +
                    "        <a-input v-model:value=\"form.%s\" placeholder=\"请输入%s\"/>\n" +
                    "      </a-form-item>\n", column.get("columnComment"), StrUtil.toCamelCase(columnName),column.get("columnComment"));
            }

        }
    }
}
